package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFillInsert;
import com.sky.annotation.AutoFillUpdate;
import com.sky.entity.Employee;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     *
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);

    @Select("select count(*) from employee where username = #{username}")
    Integer selectCountByUsername(String username);

    @AutoFillInsert
    void insert(Employee employee);

    Page<Employee> selectByName(Employee employeequery);

    @AutoFillUpdate
    void updateStatusById(Employee employee);

    @Select("select id,\n" +
            "       name,\n" +
            "       username,\n" +
            "       password,\n" +
            "       phone,\n" +
            "       sex,\n" +
            "       id_number,\n" +
            "       status,\n" +
            "       create_time,\n" +
            "       update_time,\n" +
            "       create_user,\n" +
            "       update_user\n" +
            "from employee\n" +
            "where id = #{id}")
    Employee selectById(Long id);

    Integer selectCountByUsernameIdNotSelf(String username, Long id);
}
